import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";

import path from "path";

const baseUrl = "http://192.168.0.107:8080"; // 后端接口

// https://vitejs.dev/config/
export default defineConfig(() => {
  return {
    server: {
      port: 8000,
      host: true,
      open: true,
      proxy: {
        "/dev-api": {
          target: baseUrl,
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/dev-api/, ""),
        },
      },
    },
    // 项目插件
    plugins: [vue()],
    // 基础配置
    base: "./",
    publicDir: "public",
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
      },
    },
    css: {
      preprocessorOptions: {
        // less: {
        //   modifyVars: {
        //     '@border-color-base': '#dce3e8',
        //   },
        //   javascriptEnabled: true,
        // },
        scss: {
          // 关键：启用新 API
          api: "modern-compiler", // 或 'modern'（vite 5.4+ 推荐 modern-compiler）
        },
      },
    },
    build: {
      outDir: "dist",
      assetsDir: "assets",
      assetsInlineLimit: 4096,
      cssCodeSplit: true,
      brotliSize: false,
      sourcemap: false,
      minify: "terser",
      terserOptions: {
        compress: {
          // 生产环境去除console及debug
          drop_console: false,
          drop_debugger: true,
        },
      },
    },
  };
});
